package com.shenjies88.practice.baseframework.controller;

import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author by shenjies88
 * @since 2025/9/14 9:39
 */

@Slf4j
@AllArgsConstructor
@RequestMapping("/chatMemory")
@RestController
public class ChatMemoryController {

    @Resource(name = "dsllmMemoryChatClient")
    private final ChatClient dsllmMemoryChatClient;

    @Resource(name = "dsllmJdbcChatClient")
    private final ChatClient dsllmJdbcChatClient;

    @GetMapping("/memoryChat")
    public String memoryChat(@RequestParam String msg) {
        ChatClient.CallResponseSpec call = dsllmMemoryChatClient.prompt()
                .advisors(a -> a.param(ChatMemory.CONVERSATION_ID, "007"))
                .user(msg)
                .call();
        return call.content();
    }

    @GetMapping("/jdbcChat")
    public String jdbcChat(@RequestParam String msg) {
        ChatClient.CallResponseSpec call = dsllmJdbcChatClient.prompt()
                .advisors(a -> a.param(ChatMemory.CONVERSATION_ID, "007"))
                .user(msg)
                .call();
        return call.content();
    }
}
